﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using FlexiCommerce.Components;

namespace FlexiCommerce.Web.UI.WebControls
{
    public class CategoryDataSource : ItemDataSource<Components.Category>, IHierarchicalDataSource
    {
        #region IHierarchicalDataSource Members

        public event EventHandler DataSourceChanged;

        public HierarchicalDataSourceView GetHierarchicalView(string viewPath)
        {
            if (string.IsNullOrEmpty(viewPath))
                return new ItemHierarchicalDataSourceView(null);

            Category cat = Find.Categories.Where(c => c.ID == int.Parse(viewPath)).SingleOrDefault();

            return new ItemHierarchicalDataSourceView((IHierarchicalPersistenceItem)cat);
        }

        #endregion
    }
}
